import type { OrderDetailResult, OrderSubmitData, OrderSubmitResult } from '@/types/order'
import request from '@/utils/request/request'

/**
 * 历史订单查询
 * @param params
 * @returns
 */
export const getOrderListAPI = (params: PageParams & { status?: number }) => {
  return request<PageResult<OrderDetailResult[]>>({
    method: 'GET',
    url: '/order/historyOrders',
    params: { ...params },
  })
}
/**
 * 提交订单
 * @param data
 * @returns
 */
export const submitOrderAPI = (data: OrderSubmitData) => {
  return request<OrderSubmitResult>({
    method: 'POST',
    url: '/order/submit',
    data: data,
  })
}
/**
 * 根据订单id获取订单详情
 * @param id
 * @returns
 */
export const getOrderDetailAPI = (id: number) => {
  return request<OrderDetailResult>({
    method: 'GET',
    url: `/order/${id}`,
  })
}
/**
 * 根据id删除订单
 * @param id
 * @returns
 */
export const deleteOrderAPI = (id: number) => {
  return request({
    method: 'DELETE',
    url: '/order',
    params: { id },
  })
}
/**
 * 取消订单
 * @param id
 * @returns
 */
export const cancelOrderAPI = (id: number) => {
  return request({
    method: 'PUT',
    url: `/order/cancel/${id}`,
  })
}
/**
 * 再来一单
 * @param id
 * @returns
 */
export const repetitionOrderAPI = (id: number) => {
  return request({
    method: 'POST',
    url: `/order/repetition/${id}`,
  })
}
/**
 * 订单支付（模拟支付）
 * @param orderNumber
 * @param payMethod
 * @returns
 */
export const paymentOrderAPI = (orderNumber: string, payMethod: number) => {
  return request({
    method: 'PUT',
    url: '/order/myPayment',
    data: { orderNumber, payMethod },
  })
}
